package com.thortec.farmsys.config;


import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.thortec.farmsys.utils.SpringContextUtils;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * webconfig
 *
 * @auther ny by:dbw
 * @create 2018-06-09
 */
@Configuration
public class WebConfig {

    @Bean
    public SpringContextUtils springContextUtils(){
        return new SpringContextUtils();
    }

    /**
     * 替换springboot默认的response处理的jackon解析器 使用阿里巴巴fastjson进行默认处理
     * @return
     */
    @Bean
    public HttpMessageConverters fastJsonHttpMessageConverters(){
        //1.需要定义一个convert转换消息的对象;
        FastJsonHttpMessageConverter fastJsonHttpMessageConverter = new FastJsonHttpMessageConverter();
        //3处理中文乱码问题
        List<MediaType> fastMediaTypes = new ArrayList<>();
        fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
         //4.在convert中添加配置信息.
        fastJsonHttpMessageConverter.setSupportedMediaTypes(fastMediaTypes);
//        fastJsonHttpMessageConverter.setFeatures(SerializerFeature.WriteMapNullValue);
        HttpMessageConverter<?> converter = fastJsonHttpMessageConverter;
        return new HttpMessageConverters(converter);

    }

}
